<?php
if(!empty($_POST['hidSellerReply'])) { 
	if($_POST['hidType']=="delete") {
		$sqlDelReply="DELETE FROM tbl_bargain WHERE bargain_id='".$_POST['hidSellerReply']."'";
		$rstDelReply=mysql_query($sqlDelReply) or die(mysql_error());									
		$affectedRow= mysql_affected_rows();
		if($affectedRow>0) { 
			$sqlDelOfffer = "DELETE FROM tbl_bargain WHERE parent_id='".$_POST['hidSellerReply']."'";
			$rstDelOffer = mysql_query($sqlDelOfffer) or die(mysql_error());
			if(mysql_affected_rows()>0) {
				echo "<div id='suc-msg'>Offer deleted.</div>"; 
			}
		}
		else { 
			echo "<div id='err-msg'>Error on deleting your reply.</div>"; 
		}
	}	
}
?>
<script type="text/javascript">		
	
	function funDeleteBargain(bargain) {
		
		frm = document.frmProductOffer;
		document.getElementById("hidSellerReply").value=bargain;
		document.getElementById("hidType").value="delete";
		frm.submit();		
	}
	
</script>
<style type="text/css">
	div.reply { padding:5px; border:1px solid #CCC; }
	div.reply label { float:left; width:100px; }
</style>
<div style="border-bottom:1px solid #CCC;"></div>
<div style="font-weight:bold; padding:2px;" class="tdHeader">Questions and Offers</div>
<div style="border-bottom:1px solid #CCC;"></div><br>
<form name="frmProductOffer" action="" method="post" id="frmProductOffer">
	<input type="hidden" name="hidSellerReply" id="hidSellerReply">	
	<input type="hidden" name="hidType" id="hidType">
<?php
    $sqlProOffers="SELECT * FROM tbl_bargain where item_id='$proId' and status='offer'";
	$rstProOffers=mysql_query($sqlProOffers);
	$noProOffers=mysql_num_rows($rstProOffers);		
		if($noProOffers > 0) { 
	while($rowProOffers = mysql_fetch_array($rstProOffers))
				$pro_offers[]=$rowProOffers; 
	}
	if(is_array($pro_offers) > 0) { ?>
		<table width='100%' border='0' align='center' cellspacing='0' cellpadding='0'>	
		<?php $i=0;
		foreach($pro_offers as $offer) { ?>
			<tr>
			  <td>&nbsp;</td>
		    <td height="30"><strong>Offer</strong></td><td><strong>Price</strong></td></tr>
			<tr>
			    <td width='3%'>&nbsp;</td>
				<td width='85%'><?php echo $offer['comment']; ?></td>
				<td width='12%'>$<?php echo number_format($offer['offer_amount'],2); ?>
				<br>							
				<input type="button" class="button" onClick="funDeleteBargain('<?php echo $offer['bargain_id']; ?>');" value="Delete">
						
				</td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td colspan='2'>				 
				<?php 
				$sqlSelparent="SELECT * FROM tbl_bargain where parent_id='".$offer['bargain_id']."' and item_id='$proId'";
		        $rstSelparent=mysql_query($sqlSelparent);
			    $pro_reply= mysql_fetch_array($rstSelparent); ?>
			</td></tr>
			<?php if($pro_reply!="") { ?>
			<tr bgcolor="#CCCCCC">
			  <td>&nbsp;</td>
		    <td height="30"><strong>Seller's Response</strong></td><td><strong>Price</strong></td></tr>
			<tr bgcolor="#CCCCCC">
			  <td width='3%'>&nbsp;</td>
				<td width='85%'><?php echo $pro_reply['comment']; ?> </td>
				<td width='12%'>$<?php echo number_format($pro_reply['asking_amount'],2); ?>
					<br>							
					<input type="button" class="button" onClick="funDeleteBargain('<?php echo $pro_reply['bargain_id']; ?>');" value="Delete">					
				</td>
			</tr>
			<tr bgcolor="#CCCCCC">
			  <td>&nbsp;</td>
			  <td>&nbsp;</td>
			  <td>&nbsp;</td>
		  </tr>	
			<?php } 
		$i++; 
	      } ?> 
		</table>
		<?php
	}
	else { echo "<br>No Offers found.";	 }

?>
</form>
